<script type="text/javascript">
var isSelected;
var uid;

$(document).ready(function(){
	 var data = JSON.parse($(".s_temple_setting.send_leave_message").html());
	 isSelected = data.isSelected;
	 if(isSelected){
		$("#s_lm_s_search").hide();
		$(".s_lm_s_targetheader").attr("src",data.card.head_image_path);
		$(".s_lm_s_targetname").html(data.card.name);
		$(".s_lm_targetuid").attr("value",data.uid);
		console.log(data);
		if(data.isReply){
			$(".s_lm_s_quote").html(new Base64().decode(data.reply));
			$(".s_lm_targetreply").attr("value",data.replyid);
		}else{
			$(".s_lm_s_reply").hide();
		}
	}else{
		$("#s_lm_s_send").hide();
	}
	 bindAjaxForm($("#s_lm_s_send"),s_lm_s_onSuccess,s_lm_s_onError);
	 bindAjaxForm($("#s_lm_s_search"),s_lm_s_onSuccess,s_lm_s_onError);
});
function s_lm_s_onSuccess(data){
	console.log(data);
	s_lm_s_operatedone(data.code,data.message,data.data);
}
function s_lm_s_onError(data){
	console.log(data);
	s_lm_s_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_lm_s_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_lm_s_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0){
		showMessage("s_lm_s_message",id,message);
		return;
	}else{
		$("#s_lm_s_message").addClass("hidden");
	}
	op = data.op;
	if(op=="search"){
		$("#s_lm_s_search").hide();
		$("#s_lm_s_send").show();
		$(".s_lm_s_targetheader").attr("src",data.card.head_image_path);
		$(".s_lm_s_targetname").html(data.card.name);
		$(".s_lm_targetuid").attr("value",data.uid);
		if(data.isReply){
			$(".s_lm_s_quote").html(data.reply);
			$(".s_lm_targetreply").attr("value",data.replyid);
		}else{
			$(".s_lm_s_reply").hide();
		}
	}
	if(op=="send"){
		showMessage("s_lm_s_message",0,"您的留言已发送");
		$("#s_lm_s_send").hide();
		$("#s_lm_s_search").hide();
	}
}
</script>
<h2>发送留言</h2>
<div class="s_temple_setting send_leave_message"><?php print_json_setting("send_leave_message");?></div>
<div class="ui message hidden" id="s_lm_s_message"></div>
<form class="ui form" url="index.php?mod=home&childmod=notice&ajax=true&op=leavemessage_search" id="s_lm_s_search">
	<div class="ui action fluid input">
		<div class="ui left icon input">
			<input type="text" name="account" placeholder="请输入你要留言对象的账号来查询">
			<i class="users icon"></i>
		</div>
		<button class="ui button submit" type="submit">确定</button>
	</div>
</form>
<form class="ui form" url="index.php?mod=home&childmod=notice&ajax=true&op=leavemessage_send" id="s_lm_s_send">
	<input class="s_lm_targetuid" type="hidden" name="uid">
	<input class="s_lm_targetreply" type="hidden" name="reply" value="-1">
	<div class="field inline">
		<label>发送对象：</label>
		<img class="ui avatar image s_lm_s_targetheader">
		<span class="s_lm_s_targetname"></span>
	</div>
	<div class="field s_lm_s_reply">
		<label>回复对象：</label>
		<span class="s_lm_s_quote"> </span>
	</div>
	<div class="field">
		<label>留言信息</label>
		<input type="text" name="content" placeholder="留言内容">
	</div>
	<button class="ui button submit" type="submit">确定</button>
	<div class="ui error message"></div>
</form>